<template>
  <div class="right-block3">
    <div class="display-flex">
      <div class="box2 sm-title text-right">
        <span class="num color-red">{{ dataListbj.length }}</span
        >报警事件 <span class="num color-yellow">{{  dataListbj1.length  }}</span
        >事件处理
      </div>
    </div>

    <template v-if="dataListbj && dataListbj.length > 0">
      <vue-seamless-scroll
        :data="dataListbj"
        class="seamless-warp"
        :class-option="classOption"
      >
        <ul class="item">
          <li  style="height: 38px;font-size: 14px; text-align: center;"  v-for="(item, index) in dataListbj"  :key="index" >
             
            <label v-if="item.bjtype == 1">
              <span style="color: yellow" v-if="item.bjtype == 1">质量</span>
              <span style="color: yellow" class="title">{{  item.gateway.name }}</span>
              <span style="color: yellow" v-if="item.bjlx == 1001"  >焊接电流</span >
              <span style="color: yellow" v-if="item.bjlx == 1002"  >焊接电压</span >
              <span style="color: yellow" v-if="item.bjlx == 1003"  >焊接速度</span >
              <span style="color: yellow" v-if="item.bjlx == 1004">气流量</span>
              <span style="color: yellow" v-if="item.bjlx == 1005" >焊接温度</span >
              <span style="color: yellow" v-if="item.bjtype == 1" >超出工艺规程</span >
              <span  style="color: yellow"  class="date"  v-text="item.gjtime" ></span>
            </label>
            <span style="color: orange" v-if="item.bjlx == 2001">
               <label v-if="item.bjtype == 2">
                安全  {{  item.gateway.name  }}  风速  超出设定值  {{item.gjtime}} 
            </label>
            </span> 
            <span style="color: orange" v-if="item.bjlx == 2002">
              安全  {{  item.gateway.name  }}  温度  超出设定值  {{item.gjtime}} 
              </span>
              <span style="color: orange" v-if="item.bjlx == 2003">
                安全  {{  item.gateway.name  }}  湿度  超出设定值  {{item.gjtime}} 
              </span>
 
              <span style="color: red" v-if="item.bjlx == 2004">
                安全  {{  item.gateway.name  }}  甲烷  超出设定值  {{item.gjtime}} 
              </span>
              <span style="color: red" v-if="item.bjlx == 2005">
                安全  {{  item.gateway.name  }}  氧气  超出设定值  {{item.gjtime}} 
              </span>
              <span style="color: red" v-if="item.bjlx == 2006">
                安全  {{  item.gateway.name  }}  一氧化碳  超出设定值  {{item.gjtime}} 
              </span>
              <span style="color: red" v-if="item.bjlx == 2007">
                安全  {{  item.gateway.name  }}  硫化氢  超出设定值  {{item.gjtime}} 
              </span>
          </li>
        </ul>
      </vue-seamless-scroll>
    </template>
    <div v-else class="nodata">
      <img src="~@/assets/img/nobg.png" />
      <div class="txt">暂无数据</div>
    </div>
  </div>
</template>

<script>
import vueSeamless from "vue-seamless-scroll";
import { postHandle } from "@/api";
import AutoRefreshMixin from "../mixin/AutoRefreshMixin";
export default {
  name: "EquipmentAlarm",
  components: {
    "vue-seamless-scroll": vueSeamless,
  },
  mixins: [AutoRefreshMixin],
  props: {
    newSpaceId: {
      type: String,
    },
  },
  data() {
    return {
      fault: 0,
      alarm: 0,
      dataListbj: [],
      dataListbj1: [],
    };
  },
  computed: {
    spaceId() {
      return this.$store.state.project.spaceId;
    },
    classOption() {
      return {
        step: 0.3,
        singleHeight: 100,
        direction: 1,
        limitMoveNum: 1,
      };
    },
  },
  watch: {
    newSpaceId(val) {
      if (val) {
        this.autoRefreshHandle();
      }
    },
  },

  mounted() {
    this.autoRefreshHandle();
  },
  methods: {
    refreshHandle() {
      this.getData();
      // this.equipmentFault()
      this.equipmentAlarm();
    },
    getData() {
      var date = new Date();
      var year = date.getFullYear(); //月份从0~11，所以加一
      let month = date.getMonth();
     
      var dateArr = [
        date.getMonth() + 1,
        date.getDate(),
        date.getHours(),
        date.getMinutes(),
        date.getSeconds(),
      ];
      //如果格式是MM则需要此步骤，如果是M格式则此循环注释掉
      for (var i = 0; i < dateArr.length; i++) {
        if (dateArr[i] >= 1 && dateArr[i] <= 9) {
          dateArr[i] = "0" + dateArr[i];
        }
      }
      var strDate = year + "-" + dateArr[0] + "-" + dateArr[1];
      postHandle("/api/v1/welder-sbtx-second/eq-alarm-comb/getList", {
        d: {
          fields: [
            {
              name: "userInfo", // 返回用户拥有的角色
            },
            {
              name: "deviceInfo", // 返回用户拥有的角色
            },
            {
              name: "disposeRecord",
            },
          ],
          filters: [
            {
              field: "spaceId",
              operator: "EQUALS",
              value: this.newSpaceId || this.spaceId,
            },
            {
              field: "gjtime",
              operator: "LIKE",
              value: strDate,
            },
            {
              field: "st",
              operator: "EQUALS",
              value: 1,
            } 
            
            
            // {
            //   field: "status",
            //   operator: "EQUALS",
            //   value: 2,
            // },
          ],
          page: {
            ps: 20,
          },
          sorts: [{ field: "alramTime", isDesc: true }],
        },
      }).then((res) => {
       
        this.dataListbj=res.result;
       
      });


      postHandle("/api/v1/welder-sbtx-second/eq-alarm-comb/getList", {
        d: {
          fields: [
            {
              name: "userInfo", // 返回用户拥有的角色
            },
            {
              name: "deviceInfo", // 返回用户拥有的角色
            },
            {
              name: "disposeRecord",
            },
          ],
          filters: [
            {
              field: "spaceId",
              operator: "EQUALS",
              value: this.newSpaceId || this.spaceId,
            },
            {
              field: "gjtime",
              operator: "LIKE",
              value: strDate,
            },
            {
              field: "st",
              operator: "EQUALS",
              value: 2,
            } 
            
            
            // {
            //   field: "status",
            //   operator: "EQUALS",
            //   value: 2,
            // },
          ],
          page: {
            ps: 20,
          },
          sorts: [{ field: "alramTime", isDesc: true }],
        },
      }).then((res) => {
       
        this.dataListbj1=res.result;
       
      });
    },
    // equipmentFault() {
    //   postHandle('/api/v1/welder-sbtx-second/equipment-alarm/count', {
    //     d: {
    //       filters: [
    //         {
    //           field: 'status',
    //           operator: 'EQUALS',
    //           value: 2
    //         },
    //         {
    //           field: 'spaceId',
    //           operator: 'EQUALS',
    //           value: this.spaceId
    //         }
    //       ]
    //     }
    //   }).then(res => {
    //     this.fault = res.result
    //   })
    // },
    equipmentAlarm() {
      postHandle(
        "/api/v1/welder-mw-second/monitor-alarm-record-comb/get-alarm-record-status-count",
        {
          d: {},
          obj: {
            spaceId: this.newSpaceId || this.spaceId,
            notRepair: true,
          },
        }
      ).then((res) => {
        this.fault = res.result.faultCount;
        this.alarm = res.result.alarmCount;
      });
    },
  },
};
</script>

<style scoped>
.seamless-warp {
  height: 280px;
  overflow: hidden;
}
</style>
